ASP.NET Core包含三個篩選準則,可用於 Antiforgery Token:
ValidateAntiForgeryToken 可以套用至 Action、Controller 或全域Action。 如果 Request 不包含有效的 Antiforgery Token,會遭到封鎖。
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Index()
{
    // ...
    return RedirectToAction();
}
IgnoreAntiforgeryToken 可以套用至全域或是指定 Action 、Controller 取消驗證 AntiforgeryToken。
[IgnoreAntiforgeryToken]
public IActionResult IndexOverride()
{
    // ...
    return RedirectToAction();
}
AutoValidateAntiforgeryToken 屬性的運作方式與 ValidateAntiForgeryToken 屬性相同,但AutoValidateAntiforgeryToken只針對不安全的 HTTP Methods 進行自動驗證,會忽略下列
GET
HEAD
OPTIONS
TRACE[IgnoreAntiforgeryToken],就會自動排除驗證 AntiforgeryToken。(在非Web API的專案上建議使用這個)類別層級範例
[AutoValidateAntiforgeryToken]
public class HomeController : Controller
全域範例
builder.Services.AddControllersWithViews(options =>
{
    options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
在使用者通過驗證之後,應該重新整理 Token,方法是將使用者重新導向至檢視或 Razor 頁面。
跨站請求偽造
Prevent Cross-Site Request Forgery (XSRF/CSRF) attacks in ASP.NET Core